admin: Extract ot_admin_join_config_lines() helper function
authorJavier Martinez Canillas <javier.martinez@collabora.co.uk>
Tue, 20 Aug 2013 15:54:59 +0000 (17:54 +0200)
committerColin Walters <walters@verbum.org>
Tue, 20 Aug 2013 17:00:19 +0000 (13:00 -0400)
ot-bootloader-syslinux.c has a join_lines() function that is rather
generic and can be used in other places. Let's add it as a helper
function.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
https://bugzilla.gnome.org/show_bug.cgi?id=706370

src/ostree/ot-admin-functions.h
src/ostree/ot-admin-util.c
src/ostree/ot-bootloader-syslinux.c

index a77147281c246373e2ae2a143e741b506d02a397..61f8b23b226c29a0c61a860eef4f9ed785d3ec22 100644 (file)
@@ -38,6 +38,8 @@ gboolean ot_admin_util_get_devino (GFile         *path,
                                    GCancellable  *cancellable,
                                    GError       **error);
 
+char *ot_admin_join_lines (GPtrArray  *lines);
+
 gboolean ot_admin_parse_deploy_path_name (const char *name,
                                           char      **out_csum,
                                           int        *out_serial,
index affe6db05c304bb852ba3eb1cb13e301bcc91b9e..4a055788b93601f73197dffcc4dd5b4bc526a272 100644 (file)
@@ -75,3 +75,27 @@ ot_admin_util_get_devino (GFile         *path,
  out:
   return ret;
 }
+
+char *
+ot_admin_join_lines (GPtrArray  *lines)
+{
+  GString *buf = g_string_new ("");
+  guint i;
+  gboolean prev_was_empty = FALSE;
+
+  for (i = 0; i < lines->len; i++)
+    {
+      const char *line = lines->pdata[i];
+      /* Special bit to remove extraneous empty lines */
+      if (*line == '\0')
+        {
+          if (prev_was_empty || i == 0)
+            continue;
+          else
+            prev_was_empty = TRUE;
+        }
+      g_string_append (buf, line);
+      g_string_append_c (buf, '\n');
+    }
+  return g_string_free (buf, FALSE);
+}
index 27eae45ff19e22f68c9c094cb4f8de3bfa0f347a..790db09a53f62f3602086916ad29342e52e31c80 100644 (file)
@@ -104,30 +104,6 @@ append_config_from_boot_loader_entries (OtBootloaderSyslinux  *self,
   return ret;
 }
 
-static char *
-join_lines (GPtrArray  *lines)
-{
-  GString *buf = g_string_new ("");
-  guint i;
-  gboolean prev_was_empty = FALSE;
-
-  for (i = 0; i < lines->len; i++)
-    {
-      const char *line = lines->pdata[i];
-      /* Special bit to remove extraneous empty lines */
-      if (*line == '\0')
-        {
-          if (prev_was_empty || i == 0)
-            continue;
-          else
-            prev_was_empty = TRUE;
-        }
-      g_string_append (buf, line);
-      g_string_append_c (buf, '\n');
-    }
-  return g_string_free (buf, FALSE);
-}
-
 static gboolean
 ot_bootloader_syslinux_write_config (OtBootloader          *bootloader,
                                      int                    bootversion,
@@ -253,7 +229,7 @@ ot_bootloader_syslinux_write_config (OtBootloader          *bootloader,
                                                cancellable, error))
     goto out;
 
-  new_config_contents = join_lines (new_lines);
+  new_config_contents = ot_admin_join_lines (new_lines);
 
   if (strcmp (new_config_contents, config_contents) != 0)
     {